// 用户相关类型
export interface User {
  id: string
  email: string
  username: string
  displayName?: string
  avatar?: string
  bio?: string
  phone?: string
  birthday?: Date
  createdAt: string
  updatedAt: string
  partnerId?: string
  isOnline?: boolean
  lastSeen?: string
}

// 伙伴关系相关类型
export interface Partner {
  id: string
  inviteCode: string
  createdAt: string
  updatedAt: string
  users: User[]
  isActive: boolean
}

// 消息相关类型
export interface Message {
  id: string
  content: string
  type: 'text' | 'image' | 'file' | 'system'
  senderId: string
  receiverId: string
  createdAt: string
  updatedAt: string
  sender?: User
  receiver?: User
  isRead?: boolean
  readAt?: string
  metadata?: {
    fileName?: string
    fileSize?: number
    mimeType?: string
    imageUrl?: string
    thumbnailUrl?: string
  }
}

// 计划相关类型
export interface Plan {
  id: string
  title: string
  description?: string
  status: 'draft' | 'active' | 'completed' | 'cancelled'
  priority: 'low' | 'medium' | 'high'
  dueDate?: string
  createdById: string
  partnerId: string
  createdAt: string
  updatedAt: string
  tasks: Task[]
  createdBy?: User
}

// 任务相关类型
export interface Task {
  id: string
  title: string
  description?: string
  isCompleted: boolean
  completedAt?: string
  completedById?: string
  planId: string
  createdAt: string
  updatedAt: string
  completedBy?: User
}

// 相册相关类型
export interface Album {
  id: string
  name: string
  description?: string
  coverPhotoId?: string
  partnerId: string
  createdAt: string
  updatedAt: string
  photos: Photo[]
  coverPhoto?: Photo
}

export interface Photo {
  id: string
  filename: string
  originalName: string
  mimeType: string
  size: number
  url: string
  thumbnailUrl?: string
  description?: string
  takenAt?: string
  uploadedById: string
  albumId: string
  createdAt: string
  updatedAt: string
  uploadedBy?: User
}

// 游戏相关类型
export interface GameRoom {
  id: string
  type: 'gomoku' | 'tic-tac-toe'
  status: 'waiting' | 'playing' | 'finished'
  currentPlayerId?: string
  winnerId?: string
  gameData: any
  partnerId: string
  createdAt: string
  updatedAt: string
  players: User[]
}

// 通知相关类型
export interface Notification {
  id: string
  type: 'message' | 'plan' | 'task' | 'game' | 'system'
  title: string
  content: string
  isRead: boolean
  readAt?: string
  userId: string
  relatedId?: string
  createdAt: string
  updatedAt: string
}

// API 响应类型
export interface ApiResponse<T = any> {
  success: boolean
  data?: T
  message?: string
  error?: string
}

export interface PaginatedResponse<T> {
  data: T[]
  pagination: {
    page: number
    limit: number
    total: number
    totalPages: number
    hasNext: boolean
    hasPrev: boolean
  }
}

// 认证相关类型
export interface LoginCredentials {
  username: string
  password: string
}

export interface RegisterData {
  username: string
  password: string
  nickname?: string
}

export interface AuthTokens {
  accessToken: string
  refreshToken: string
}

export interface AuthResponse {
  user: User
  tokens: AuthTokens
}

// 表单相关类型
export interface FormField {
  name: string
  label: string
  type: 'text' | 'email' | 'password' | 'textarea' | 'select' | 'file' | 'date'
  placeholder?: string
  required?: boolean
  validation?: {
    minLength?: number
    maxLength?: number
    pattern?: RegExp
    custom?: (value: any) => string | undefined
  }
  options?: { label: string; value: string }[]
}

// Socket.IO 事件类型
export interface SocketEvents {
  // 连接事件
  connect: () => void
  disconnect: () => void
  
  // 消息事件
  'message:new': (message: Message) => void
  'message:read': (data: { messageId: string; userId: string }) => void
  
  // 输入状态事件
  'typing:start': (data: { userId: string; partnerId: string }) => void
  'typing:stop': (data: { userId: string; partnerId: string }) => void
  
  // 在线状态事件
  'user:online': (data: { userId: string }) => void
  'user:offline': (data: { userId: string }) => void
  
  // 游戏事件
  'game:move': (data: { roomId: string; move: any }) => void
  'game:end': (data: { roomId: string; winnerId?: string }) => void
  
  // 通知事件
  'notification:new': (notification: Notification) => void
}

// 主题相关类型
export type Theme = 'light' | 'dark' | 'system'

// 语言相关类型
export type Language = 'zh-CN' | 'en-US'

// 应用状态类型
export interface AppState {
  theme: Theme
  language: Language
  isLoading: boolean
  error?: string
}

// 聊天状态类型
export interface ChatState {
  messages: Message[]
  isTyping: boolean
  typingUsers: string[]
  isLoading: boolean
  hasMore: boolean
}

// 文件上传类型
export interface UploadProgress {
  file: File
  progress: number
  status: 'pending' | 'uploading' | 'success' | 'error'
  error?: string
  url?: string
}